package com.yjx.util;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Component
public class RedisUtil {
    @Resource
    private RedisTemplate redisTemplate;
    //put
    public void put(String key, String value) {
        ValueOperations<String,String> valueOperations=   redisTemplate.opsForValue();
        valueOperations.set(key,value);
    }


    public void put(String key, String value, Long timeOut, TimeUnit timeUnit) {
        ValueOperations<String,String> valueOperations=redisTemplate.opsForValue();
        valueOperations.set(key, value, timeOut, timeUnit);
    }
    //get

    public String get(String key) {
        ValueOperations<String,String> valueOperations=redisTemplate.opsForValue();
        String value = valueOperations.get(key);
        return value;
    }


    //delete
    public void delete(String key) {
        redisTemplate.delete(key);
    }
}
